<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
	<title>去保养底至0元保养</title>
	<link rel="stylesheet" type="text/css" href="{:C('WEB_URL')}Public/css/base.css">
	<link rel="stylesheet" type="text/css" href="{:C('WEB_URL')}Public/mobile/css/master.css">
    <link rel="stylesheet" type="text/css" href="{:C('WEB_URL')}Public/mobile/css/gua.css">
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?11ad56ca0738ac14d150a362fca3e058";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>


</head>
<body>
    <header class="tcenter fs14">
        <a href="tel:4006730088" class="tel iconfont">&#xe610;</a>
        <a href="javascript:window.history.go(-1)" class="iconfont fleft">&#xe612;</a>
        刮刮赢千元免单券
    </header>
	<input type="hidden" id="date" value="{$date}"/>
	<input type="hidden" id="user_id" value="{$_SESSION['user']['user_id']}"/>
	<div class="banner">
		<img src="{:C('WEB_URL')}Public/mobile/images/banner.jpg" width="100%" style="display:block" />
	</div>

    <div id="gua">
    	<div class="people">
            <p>活动抢票人次 <em>{$AllCount['sum']}</em></p>
            <p>今日抢票人次 <em>{$AllCount['get_count']}</em></p>
        </div>
    
        <div class="guaMain guaModel">
            <p>争分夺券，享受免单</p>
            <p class="hide">每日上午11点及下午4点各开放50个名额</p>
            
            <p class="count">今天仅剩<em>{$Last}</em>个名额</p>
            <p class="timeDown"></p>
            <div class="canvas" ontouchend="gua.val()">
                <div id="prize"></div>
                <div id="scratchpad">
                    <div style="position: relative; width: 95%; height: 45px;line-height:45px;text-align:center;color:#fff; cursor: default;background:#b79645;font-size:13px;margin:0 auto"></div>
                </div>
            </div>
            <p class="hasCount">
                今日剩余机会：<em id="J_num">*</em>
                <a href="javascript:window.history.go(0)" id="J_again" class="hide">再试一次</a>
            </p>
        </div>

        <div class="guaModel q1">
            <i>Q1</i>
            <h3>什么是免单券？</h3>
            <p>通过去保养下保养订单，<em>买多少，返现多少</em>，最高可返1000元，相当于免单一次。返现金额不受下单时间和购物品类限制（注：不与站内其他优惠同享）。绝对超值哟！</p>
        </div>

        <div class="guaModel q2">
            <i>Q2</i>
            <h3>怎么使用免单券?</h3>
            <ul>
                <li><span>1</span>试试手气，刮卡领取免单券</li>
                <li><span>2</span>通过微信进入我们官网并下单。</li>
                <li><span>3</span>先支付，获得免单券返现</li>
                <li><span>4</span>支付后可在个人中心-优惠券中查看返现金额。</li>
            </ul>
        </div>
        <div class="guaModel q3">
            <i>Q3</i>
            <h3>使用免单券有哪些规则?</h3>
            <ul>
                <li>01、免单券使用时先购买后返现，买多少返现多少（返现余额以实际支付金额为准，返现余额上限为1000元，不可提现）；</li>
                <li>02、免单券与其他优惠不可同时使用；</li>
                <li>03、机油最高可抵200元；</li>
                <li><em>04、免单券仅限上海地区用户使用；</em></li>
                <li>05、商品退货需消耗免单券，否则不予退货；</li>
                <li>06、请在有效期内使用免单券，逾期作废；</li>
                <li>07、同一账号只能领取并使用一张免单券；</li>
            </ul>
        </div>
        <div class="phone">
            <div class="bg" id="J_phoneBg" ontouchstart="$('.phone').hide()"></div>
            <div class="phoneMain">
                <p>该手机号，用于绑定您将获得的免单券</p>
                <input type="tel" name="phone" id="J_phone" value="{$_SESSION['user']['username']}" placeholder="您的手机号"/>
                <a href="javascript:void(0)" onclick="gua.setPhone()">确认</a>
                <p class="tip">提示内容</p>
            </div>
        </div>
    </div>
    <include file="Public/mobileHome" />
    <script type="text/javascript" src="{:C('WEB_URL')}Public/js/jquery.11.js"></script>
    <script type="text/javascript" src="{:C('WEB_URL')}Public/mobile/js/wScratchPad.js"></script>


	<script>


		var already = "{$already}";	//是否已有优惠券
		var getCount = getCookie('getCount');
		var Dates = getCookie('Dates');
		if(Dates == $('#date').val()){
			$("#J_num").html(getCount);
		}else{
            getCount = 3;
			setCookie('getCount',getCount,86400);
			setCookie('Dates',$('#date').val(),86400);
			
			$("#J_num").html(getCount);
		}

        $(function(){
            if(already==1||already==2){ //已有名单券
                $(".hasCount").hide();
                $("#scratchpad").children("div").html("已有免单券哦，请把机会让给别人。");
            }
            if(gua.hasCount<=0){
                $("#scratchpad").children("div").html("今天已抢完！");
                $(".count").html("今天已抢完！");
            }

        })


		var gua={
            phone:"{$_SESSION['user']['username']}",
            user_id:"{$_SESSION['user']['user_id']}",
            num:getCount, // 剩余次数
            award:"",
            hasCount:{$Last},   //当前剩余总数
            initStatus:false,
            //验证是否可刮
            val:function(){
                var phone=$("#J_phone").val();
                if(!/^(13|15|18|14|17)[0-9]{9}$/.test(this.phone)){
                    $(".phone").show();
                }else if(!this.initStatus && this.num>0 && already!=1&&already!=2 && this.hasCount>0){
                    this.init();
                }
            },
            setPhone:function(){
                var phone=$("#J_phone").val();
                if(!/^(13|15|18|14|17)[0-9]{9}$/.test(phone)){
                    $(".phone").find(".tip").show().html("您的手机号格式有误");
                }else{
                    $(".phone").find(".tip").show().html("正在努力处理中...");
                    this.phone=phone;
                    this.valPhoneToServer();
                    
                }
            },

            //服务端验证手机号
            valPhoneToServer:function(){
                var _t=this;
                $.ajax({
                    url:"{:U('verifyUser')}",
                    type:"post",
                    data:{"phone":_t.phone},
                    dataType:"json",
                    success:function(res){

                        if(res.status==1){  //手机号验证成功
                            _t.init(res.data);
                            $('#user_id').val(res.data.user_id);
                            $(".phone").hide();
                            window.location.reload();//用户登录后刷新此页面
                        }else{
                            $(".phone").find(".tip").show().html(res.info);
                        }
                    }
                })
            },

            //界面初始化
            init:function(){
                var _t=this,
                    w=$("#scratchpad").width()*0.95;

                _t.initStatus=true;
                //刮刮卡初始化
                $("#scratchpad").html("");
                $("#scratchpad").wScratchPad({
                    width: w,
                    height: 40,
                    color: "#b79645",
                    scratchDown: function() {
                        if(_t.num==0&&_t.award==""){
                            _t.award="今日抢券次数已用完";
                            $("#J_again").hide();
                        }else if(_t.award==""){
                            $.ajax({
                                url:"{:U('getCoupon')}",
                                type:"post",
                                data:{"user_id":$('#user_id').val()},
                                dataType:"json",
                                success:function(res){
                                    if(res.status==1){  //刮中
                                        already=1;
                                        $(".hasCount").hide();

                                    }else if(res.status==-1002){    //已抢完

                                    }else if(res.status==-1003){    //未刮中
                                        var Ct = FloatSub(getCount,1);
                                        setCookie('getCount',Ct,86400);
                                        $("#J_num").html(Ct);
                                        _t.num=Ct;
                                        if(Ct>0){
                                            $("#J_again").show();
                                        }
                                    }
                                    if(res.data==0){
                                        $(".count").html("当前时段已抢完！");
                                    }else{
                                        $(".count > em").html(res.data.count);    //当前剩余量
                                    }
                                    
                                    _t.award=res.info;
                                    
                                    document.getElementById('prize').innerHTML =_t.award;
                                }
                            })
                        }
                    },

                   
                });
            },

            //倒计时相关
            nowTimeS:"{$time}", //服务端时间
            nowTimeL:Date.parse(new Date())/1000,   //本地时间
            time1:new Date("{$date} 11:00").getTime()/1000,//当天上午开放时间
            time2:new Date("{$date} 16:00").getTime()/1000,//当天下午开放时间
            timeInit:function(){
                if(this.nowTimeS<this.time1){
                    this.printTime();

                }else if(this.nowTimeS<this.time2&&!this.hasCount>0){
                    this.printTime();
                }
            },
            printTime:function(){
                var _t=this,
                    cha=this.nowTimeS-this.nowTimeL;
                t=this.time2-Date.parse(new Date())/1000+cha;

                if(t<=0){
                    clearTimeout(window.timeDown);

                    _t.init();
                }else{
                    window.timeDown=setTimeout(function(){
                        var html="倒计时：",
                            h=Math.floor(t/3600);
                            m=Math.floor((t%3600)/60);
                            s=t%60;
                        
                        html+=h>9?h:"0"+h;
                        html+=":"+(m>9?m:"0"+m);
                        html+=":"+(s>9?s:"0"+s);
                        $("#scratchpad > div").html(html);
                        _t.printTime();
                    },1000);
                }
            }
        }

        if(already==""){
            //gua.timeInit();
        }

		//浮点数减法运算  
		function FloatSub(arg1,arg2){  
    		var r1,r2,m,n;  
    		try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}  
    		try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}  
    		m=Math.pow(10,Math.max(r1,r2));  
    		//动态控制精度长度  
    		n=(r1>=r2)?r1:r2;  
    		return ((arg1*m-arg2*m)/m).toFixed(n);  
		} 


	</script>
</body>
</html>